package by.bsu.fpmi.bbtp.entities;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlType;

@XmlType(namespace = "entities.fpmi.bsu.by", name = "Order")
@Entity
@Table(name = "orders")
public class Order {

    @XmlType(namespace = "entities.fpmi.bsu.by", name = "OrderState")
    public static enum State {
        CREATED, READY_TO_SEND, SENT_TO_CLIENT;
    }

    @XmlType(namespace = "entities.fpmi.bsu.by", name = "OrderType")
    public static enum Type {
        ORDINARY, FOR_RETURN;
    }

    private long id;
    private long clientId;
    private long transportCompanyId;
    private long goodId;
    private long quantity;
    private String address;
    private State state;
    private Type type;

    @Transient
    public OrderHead getHead() {
        OrderHead head = new OrderHead();
        head.setId(id);
        head.setAddress(address);
        return head;
    }

    @Id
    @GeneratedValue(generator = "increment")
    @GenericGenerator(name = "increment", strategy = "increment")
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Column(name = "client_id", nullable = false)
    public long getClientId() {
        return clientId;
    }

    public void setClientId(long clientId) {
        this.clientId = clientId;
    }

    @Column(name = "state", nullable = false)
    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    @Column(name = "type", nullable = false)
    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    @Column(name = "transport_company_id")
    public long getTransportCompanyId() {
        return transportCompanyId;
    }

    public void setTransportCompanyId(long transportCompanyId) {
        this.transportCompanyId = transportCompanyId;
    }

    public long getGoodId() {
        return goodId;
    }

    public void setGoodId(long goodId) {
        this.goodId = goodId;
    }

    public long getQuantity() {
        return quantity;
    }

    public void setQuantity(long quantity) {
        this.quantity = quantity;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}
